package com.zhiqianbao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhiqianbao.R;

import java.util.ArrayList;
import java.util.List;


//自定义的二级分类Adapter
public class ListViewOneLineTextAdapter extends BaseAdapter {
	LayoutInflater layoutInflater = null;
	ViewHolder viewHolder = null;
	List<String> listData = null;

	public ListViewOneLineTextAdapter(Context context, String[] data) {
		this.layoutInflater = LayoutInflater.from(context);
		listData = new ArrayList<String>();
		if (data != null)
			for (int i = 0; i < data.length; i++) {
				listData.add(data[i]);
			}
	}

	public ListViewOneLineTextAdapter(Context context, List<String> data) {
		this.layoutInflater = LayoutInflater.from(context);
		this.listData = data;
	}

	@Override
	public int getCount() {
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = layoutInflater.inflate(R.layout.list_item_one_line_text, null);
		viewHolder = new ViewHolder();
		viewHolder.textView = (TextView) convertView.findViewById(R.id.textView_one_line);
		convertView.setTag(viewHolder);
		viewHolder.textView.setText(listData.get(position).toString().trim());
		return convertView;
	}

	// ViewHolder
	class ViewHolder {
		TextView textView;
	}
}